﻿@using CMSMVC4
@using CMSMVC4.MultiResource
@model List<CMSMVC4.Slide>

@{
    ViewBag.Title = "Slide Show";
    Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
}
<script language="javascript" type="text/javascript">
    function dellall() {
        var chek = $('#checkall').is(':checked');
        if (chek == true) {
            $(".checker span").attr('class', "checked");
            $(".dell").attr('checked', true);
        } else {
            $(".checker span").attr('class', "");
            $(".dell").attr('checked', false);

        }
    }
    function senddell() {
        var id = [];
        $(".dell:checked").each(function () {
            var v = $(this).attr("index");
            id.push(v);
        });
        if (id.length > 0) {
            var cf = confirm("Bạn có chắc chắn muốn xóa không?");
            if (cf == true) {
                $.ajax({
                    type: "Post",
                    dataType: "json",
                    contentType: 'application/json; charset=utf-8',
                    url: "/Admin/SlideShow/Xoa",
                    data: JSON.stringify(id),
                    success: function () {
                        window.location = "/Admin/SlideShow";
                    }
                });
            }
        } else {
            alert("Hãy chọn bưu gửi muốn xóa!");
        }
    }
</script>

@if(Model !=null){
        @Html.ValidationSummary()
using (Html.BeginForm("Index", "Slideshow", FormMethod.Post))
{
    <div class="row-fluid">
        <div class="box color_10">
            <div class="title">
                <h4><span>Slide Show<small></small></span></h4>
            </div>
            <div class="content top">
                <table id="datatable_example" class="responsive table table-striped table-bordered" style="width: 100%">
                    <thead>
                        <tr>
                            <th class="jv no_sort">
                            <label class="checkbox ">
                                <input type="checkbox" id="checkall" onchange="dellall()" />
                            </label>
                        </th>
                            <th class="" style="display: none">ID</th>
                            <th class="to_hide_phone">@Admin.Images</th>
                            <th class="">Url</th>
                            <th class="">@Admin.Url</th>
                            <th class="">@Admin.Actions</th>
                        </tr>
                    </thead>
                    <tbody>
                        @for (int i = 0; i < Model.Count; i++)
                            {
                                <tr>
                                    <td>
                                @Html.CheckBox("status", new { @class = "dell", index = Model[i].Id })
                            </td>
                                    <td class="" style="display: none">@Html.HiddenFor(x => Model[i].Id)</td>
                                    <td class="">
                                        <img src="@Model[i].Image" style="width: 50px" alt=""/>
                                    </td>
                                    <td class="">@Html.TextBoxFor(x => x[i].Url, new { placeholder = "url",@class="span7" })</td>
                                    <td class="">@Html.TextBoxFor(x => x[i].Image, new { id = "Image_" + i, placeholder = "img",@class="span7" })</td>
                                    <td class="ms">
                                        <button id="Button_@i" type="button" class="btn btn-small"  rel="tooltip" data-original-title="@Admin.SelectImages"><i class="gicon-edit"></i></button>
                                        <a class="btn btn-small" onclick="senddell()"><i class="gicon-remove">
                                        </i></a>
                                    </td>
                                </tr>
                        }
                    </tbody>
                </table>
            </div>
        </div>
    </div>
    <input class="btn btn-large btn-success" type="submit" value="@Admin.SaveChange" />
    <a class="btn btn-large btn-success" href="/Admin/Slideshow/Add" style="margin-left: 30px">@Admin.UploadImage</a>
}
}
<div id="boxes">
    <div id="dialog" style="overflow: auto"></div>
    <div id="dialog_nen"></div>
</div>

<script type="text/javascript">
    $(function() {
            @for (var i = 0; i < Model.Count; i++)
            {
                  @:$("#Button_@i").click(function () {
                       @: var finder = new CKFinder();
                       @: finder.selectActionFunction = function (fileUrl) {
                       @:     $("#Image_@i").val(fileUrl);
                  @: };
                  @: finder.popup();
                  @:})
                  }
            });
</script>
